<?
//inculde即可以使用data数据。本页所有的data数据，倾在controller都处理好
include_once("../../../common/modules/checkA.php");
include_once("../../../../config.php");
include_once("../controller/detail-type-list.php");
?>





<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <link href="../asset/css/css.css" rel="stylesheet" type="text/css"/>
    <?php include ROOT_PATH_.'/controller/common/modules/head.php'; ?>
    <?php include 'modules/head.php'; ?>

</head>

<body>

<div id="topbar">
    <?php include ROOT_PATH_.'/controller/common/modules/topbar.php'; ?>
</div>

<div id="container" class="<? echo $system_part ?>">

    <div id="maincontent">

        <div id="sidebar">
            <?php include ROOT_PATH_.'/controller/common/modules/sidebar.php'; ?>
        </div>


<div id="content">
<?php $page_title='团体列表';?>
<?php include ROOT_PATH_.'/controller/common/modules/mod-page-title.php'; ?>


    <div class=" layui-form">
        <a class="layui-btn layui-btn-xs" href="detail-type-add.php?nav-itemed=cargo&sys_part=group"><i class="layui-icon">&#xe608;</i>新增</a>
    </div>

    <hr />

<!-- 用$system_part .list_boxes来控制来到确认板块信息显示-->
<div class="list-box">

<div class="list-boxes">

<table class="layui-table  layui-form">
  <colgroup>

      <col  width="60">
      <col >
      <col >
      <col >
      <col >
      <col >
	<col width="170">

  </colgroup>
  <thead>
    <tr>

      <th>序号</th>
        <th>类型名字</th>
        <th>发布状态</th>
        <th>团体人数</th>
        <th>添加时间</th>
        <th>申请人</th>
        <th>操作</th>
    </tr>
  </thead>
  <tbody>


  <?php

  if (!$root_term_list) {
      echo "<tr><td colspan='4'>暂无数据</td></tr>";
  }


	foreach($root_term_list as $key=>$detail){


        //查看有没有这个分类的子分类
        $pt['condition'] = ' term_nid ='.$detail['nid'];
        $pt['item'] = 'nid';
        $pt['table'] = $table_Prefix . "package_type";
        $term_number = count_number($pt);
    ?>

    <tr id="item<?echo $detail['nid']?>" >
        <td><?echo $key + 1 ?></td>
      <td><span class="level1_tag"> <? echo $detail['name']?></span></td>




        <td class="publish">
        <input type="checkbox" name="publish" value="<?php echo $detail['publish'];?>"
                   lay-skin="switch" lay-filter="filter"
                   id="<?php echo $detail['nid'];?>"
                   lay-text="是|否" <?if ($detail['publish'] == 1) { echo "checked"; }?> >

        </td>


        <td>再统计人数</td>


        <td><? echo $detail['add_date']?></td>
        <td><? echo  $apply_member_name_list[$detail['apply_member_nid']]?></td>


        <td>
      	  <a href="detail-type-edit.php?nid=<?php echo $detail['nid']?>&sys_part=<?echo $_REQUEST['sys_part']?>"
             class=" layui-btn  layui-btn-sm" >
			  <i class="fa fa-eye" aria-hidden="true"></i>编辑</a>
        <?php
        if(($number+$term_number) ==0){
        ?>
          <span class="layui-btn  layui-btn-sm" onclick="delItem(<?php echo $detail['nid']?>)">
              <i class="layui-icon">&#xe640;</i>删除
          </span>
    <?php }?>
      </td>
    </tr>




        <?php foreach($term_list as $k2=>$v2){
            if($detail['nid']==$v2['term_nid']){
                    $number=0;
                    //查看有没有这个分类的产品
                    $p_where['condition'] = ' term_nid ='.$v2['nid'];
                    $p_where['item'] = 'nid';
                    $p_where['table'] = $table_Prefix . "package";
                    $number = count_number($p_where);

                    ?>

                <tr >
                    <td> </td>
                    <td><span class="level2_tag">二级</span> <? echo $v2['name']?></td>
                    <td>
                        <li class="listorder bind-listorder">
                            <div class="addsub">
                                <div class="title">列表顺序</div>
                                <button type="button" class="btn-add">
                                    +
                                </button>
                                <input type="text" data-id="<?echo $v2['listorder']?>"   class="input-counter" oninput="value=value.replace(/[^\d]/g,'')" value="<? echo $v2['listorder'] ?>">
                                <button type="button" class="btn-subtract">
                                    -
                                </button>
                            </div>


                        </li>

                    </td>


                    <td class="publish">
                        <input type="checkbox" name="publish" value="<?php echo $detail['publish'];?>"
                               lay-skin="switch" lay-filter="filter"
                               id="<?php echo $v2['publish'];?>"
                               lay-text="是|否" <?if ($v2['publish'] == 1) { echo "checked"; }?> >

                    </td>
                    <td><? echo $number?></td>


                    <td>
                        <a href="detail-type-edit.php?nid=<?php echo $detail['nid']?>&sys_part=<?echo $_REQUEST['sys_part']?>"
                           class=" layui-btn  layui-btn-sm" >
                            <i class="fa fa-eye" aria-hidden="true"></i>编辑</a>
                        <?php
                        if($number ==0){
                            ?>

                            <a href="javascript:void(0)"  class="delete layui-btn  layui-btn-sm" <?php if($detail_is_disabled[$i] == 1){echo 'style= background:#ccc;cursor:not-allowed;';}else{ echo 'onclick="delItem('. $detail_nid[$i].' )"';}?> > <i class="layui-icon">&#xe640;</i> 删除</a>


                            <a class="layui-btn  layui-btn-sm"
                               href="--------detail-type-delete.php?nid=<?php echo $detail['nid']?>&sys_part=<?echo $_REQUEST['sys_part']?>">
                                <i class="layui-icon">&#xe640;</i>删除
                            </a>
                        <?php }?>
                    </td>
                </tr>
            <?}?>
        <?php;}?>



  <?php

}
?>
  </tbody>
</table>

</div>




</div>


<!--list-box end-->
</div>

<!--content端點01-->
</div>
<!--maincontent端點01-->
<br class="clearfloat"/>
</div>
<!--container端點01-->
</div>



<!--删除box-->
<?php include '../module/deletebar.php'; ?>
<!--删除box end-->




<script>
    //一般直接写在一个js文件中
    layui.use(['layer', 'form'], function(){
        var layer = layui.layer
            ,form = layui.form;

        form.on('select(MM_jumpMenu)', function(data){
            window.location.href= data.value; //得到被选中的值
        });


        form.on('switch(filter)', function(data){
            console.log(data.elem); //得到checkbox原始DOM对象
            console.log(data.elem.checked); //开关是否开启，true或者false
            console.log(data.value); //开关value值，也可以通过data.elem.value得到
            console.log(data.othis); //得到美化后的DOM对象

            updateSwitchStatus(data.elem.id,data.elem.name,data.elem.checked ? 1 : 0)
        });

        form.on('checkbox(nid-filter)', function(data){
            let checkedSum = 0;
            $("input[name='nid[]']").each(function(){
                if($(this).prop("checked")){
                    checkedSum ++;
                }
            });

            if(checkedSum > 0){
                $("#shanchu").removeClass("layui-btn-disabled");
                $("#shanchu").removeAttr("disabled")
            }else{
                $("#shanchu").addClass("layui-btn-disabled");
                $("#shanchu").attr("disabled","disabled");
            }

        });




    });







    //更新状态的 switch按钮。分类和详情的都放在一齐。
    function updateSwitchStatus(id,name,status){
        let detailListPath = [
            { key: 'publish', path: '../controller/update_publish_status.php'},
        ]
        let path = '';
        detailListPath.forEach(function (value){
            if(value.key === name){
                path = value.path
            }
        })
        //开启遮罩    常用类型。。。
        // var loading1 = layer.msg('正在加载', { icon: 16, shade: 0.3, time: 0 });
        var loading2 = layer.open({ type: 3, shade: [0.25, '#000'], icon: 2, speed: 0});

        let param = {'nid':id,'status': status}
        $.get(path,param,function(data,status){
            //关闭遮罩
            // layer.close(loading1);
            layer.close(loading2);
        });
    }








</script>





<?php include ROOT_PATH_ . "/controller/common/modules/footer.php"; ?>
</body>
</html>
